package project;

import MyNode.FSnode;
import MyNode.Node;
import repast.simphony.space.graph.Network;
import repast.simphony.space.graph.RepastEdge;
import repast.simphony.util.collections.IndexedIterable;

public class JDProject extends Project{
	private FSnode obj;
	private IndexedIterable<Object> nodes;
	private Network<Object> net;
	
	public JDProject( FSnode obj, IndexedIterable<Object> nodes, Network<Object> net) {
		this.flag=true;
		this.pmethod="JD";
		this.obj = obj;
		this.nodes = nodes;
		this.net = net;
	}


	@Override
	public void project() {
		for (int i = 0; i < nodes.size(); i++) {
			FSnode node = (FSnode) nodes.get(i);
			double weight = 0;
			if (node.getNlist() != null) {
				if (util.Arr.union(obj.getNlist(), node.getNlist()) != 0) {
					weight = (double) util.Arr.intersect(obj.getNlist(), node.getNlist())
							/ util.Arr.union(obj.getNlist(), node.getNlist());
				} else {
					weight = 0;
				}
			}
			RepastEdge<Object> edge = net.getEdge(obj, node);
			if (weight != 0) {
				if (!net.containsEdge(edge)) {
					net.addEdge(obj, node, weight);
				} else {
					edge.setWeight(weight);
				}
			} else {
				if (net.containsEdge(edge)) {
					net.removeEdge(edge);
				}
			}

		}
		
	}

}
